package com.itheima.doudizhu1;

import java.util.ArrayList;
import java.util.Collections;

public class PokerGame1 {
    //定义一个集合表示牌盒，因为牌盒在下面的洗牌发牌要用，所以定义在成员变量的位置，又因为静态代码块也要用到牌盒，所以要用static修饰
    static ArrayList<String> list = new ArrayList<>();

    //静态代码块
    //特点：随着类的加载而在加载的，而且只执行一次
    static {
        //准备牌
        // "♦", "♣", "♥", "♠"
        // "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"
        //定义一个数组存储花色
        String[] color = {"♦", "♣", "♥", "♠"};
        //定义一个数组存储牌号
        String[] number = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
        //把花色和牌号拼接起来存储到牌盒当中
        for (String c : color) {
            for (String n : number) {
                list.add(c + n);
            }
        }
        //最后再把大小王添加到牌盒当中
        list.add("大王");
        list.add("小王");
    }


    public PokerGame1() {
        //洗牌
        Collections.shuffle(list);
        //发牌
        //定义4个集合表示底牌，玩家1，玩家2，玩家3的牌
        ArrayList<String> lord = new ArrayList<>();
        ArrayList<String> player1 = new ArrayList<>();
        ArrayList<String> player2 = new ArrayList<>();
        ArrayList<String> player3 = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            if (i <= 2) {
                lord.add(list.get(i));
                continue;
            }
            if (i % 3 == 0) {
                player1.add(list.get(i));
            } else if (i % 3 == 1) {
                player2.add(list.get(i));
            } else {
                player3.add(list.get(i));
            }
        }
        //看牌
        //定义一个方法
        lookPoker("底牌",lord);
        lookPoker("钢壳儿",player1);
        lookPoker("大帅逼",player2);
        lookPoker("钢弹",player3);
    }

    /*
     * 参数一：玩家的名字
     * 参数二：每位玩家的牌
     * */
    public void lookPoker(String name, ArrayList<String> list) {
        System.out.print(name + ": ");
        for (String s : list) {
            System.out.print(s + " ");
        }
        System.out.println();
    }
}
